{
LANG : PASCAL
PROB : pizza
}

program PIZZA;
const
  fi = 'pizza.in';
  fo = 'pizza.out';
  max = 52;
var
  a : array[1..max, 1..20] of boolean;
  b : array[1..20] of byte;
  s, l : array[1..max] of integer;
  t, n, res : longint;

procedure inp;
var
  i, j, k : integer;
begin
  read(t, n);
  fillchar(a, sizeof(a), false);
  for i := 1 to n do
  begin
    read(l[i]);
    for j := 1 to l[i] do
    begin
      read(k);
      a[i, k] := true;
    end;
  end;
end;

procedure try(k : longint);
var
  ok : boolean;
  i : longint;
begin
  if k = t+1 then
  begin
    inc(res);
    exit;
  end;
  b[k] := 1;
  ok := true;
  for i := 1 to n do
    if a[i, k] then
    begin
      inc(s[i]);
      if s[i] = l[i] then ok := false;
    end;
  if ok then try(k+1);
  for i := 1 to n do
    if a[i, k] then dec(s[i]);
  b[k] := 0;
  try(k+1);
end;

procedure process;
begin
  res := 0;
  try(1);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  process;
  writeln(res);
  close(output);
  close(input);
end.